/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.knet.sp.ncrm.modules.customer.potentialadmingroup.entity;

import javax.validation.constraints.NotNull;

import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonBackReference;

import cn.knet.sp.ncrm.common.persistence.TreeEntity;
import cn.knet.sp.ncrm.common.utils.StringUtils;

/**
 * 管理员分组Entity
 * @author 葛海洋
 * @version 2015-08-25
 */
public class PotentialAdminGroup extends TreeEntity<PotentialAdminGroup> {
	
	private static final long serialVersionUID = 1L;
	private Long version = 0L;		// version
	private Date dateCreated;		// date_created
	private Date lastUpdated;		// last_updated
	private Integer levelNum;		// level_num
	private String name;		// name
	private PotentialAdminGroup parent;		// parent_id
	
	public PotentialAdminGroup() {
		super();
	}

	public PotentialAdminGroup(String id){
		super(id);
	}

	public Long getVersion() {
		return version;
	}

	public void setVersion(Long version) {
		this.version = version;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getLastUpdated() {
		return lastUpdated;
	}

	public void setLastUpdated(Date lastUpdated) {
		this.lastUpdated = lastUpdated;
	}
	
	@NotNull(message="level_num不能为空")
	public Integer getLevelNum() {
		return levelNum;
	}

	public void setLevelNum(Integer levelNum) {
		this.levelNum = levelNum;
	}
	
	@NotNull(message="分组名称不能为空")
	@Length(min=1, max=64, message="name长度必须介于 1 和 64 之间")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@JsonBackReference
	public PotentialAdminGroup getParent() {
		return parent;
	}

	public void setParent(PotentialAdminGroup parent) {
		this.parent = parent;
	}
	
	public String getParentId() {
		return parent != null && StringUtils.isNotBlank(parent.getId()) ? parent.getId() : "0";
	}

}